﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xms.Core.Context;
using Xms.CRM.Data;
using Xms.CRM.Domain;
using Xms.Data.Provider;

namespace Xms.CRM
{
    public class IntentionStudentService : IIntentionStudentService
    {
        private readonly IIntentionStudentRepository _intentionStudentRepository;

        public IntentionStudentService(IIntentionStudentRepository intentionStudentRepository
            )
        {
            _intentionStudentRepository = intentionStudentRepository;
        }

        public Guid Create(IntentionStudent entity)
        {
            return _intentionStudentRepository.CreateEntity(entity);
        }

        public bool CreateMany(List<IntentionStudent> entitys)
        {
            return _intentionStudentRepository.CreateMany(entitys);
        }

        public bool Update(IntentionStudent entity)
        {
            return _intentionStudentRepository.Update(entity);
        }

        public bool Update(Func<UpdateContext<IntentionStudent>, UpdateContext<IntentionStudent>> context)
        {
            var ctx = context(UpdateContextBuilder.Build<IntentionStudent>());
            return _intentionStudentRepository.Update(ctx);
        }

        public IntentionStudent FindById(Guid id)
        {
            return _intentionStudentRepository.FindById(id);
        }

        public bool DeleteById(Guid id)
        {
            return _intentionStudentRepository.DeleteById(id);
        }

        public bool DeleteById(List<Guid> ids)
        {
            var flag = true;
            foreach (var id in ids)
            {
                flag = this.DeleteById(id);
            }
            return flag;
            //return _repository.DeleteById(ids);
        }

        public PagedList<IntentionStudent> QueryPaged(Func<QueryDescriptor<IntentionStudent>, QueryDescriptor<IntentionStudent>> container)
        {
            QueryDescriptor<IntentionStudent> q = container(QueryDescriptorBuilder.Build<IntentionStudent>());

            return _intentionStudentRepository.QueryPaged(q);
        }

        public List<IntentionStudent> Query(Func<QueryDescriptor<IntentionStudent>, QueryDescriptor<IntentionStudent>> container)
        {
            QueryDescriptor<IntentionStudent> q = container(QueryDescriptorBuilder.Build<IntentionStudent>());

            return _intentionStudentRepository.Query(q)?.ToList();
        }

        //更新意向学员状态
        public bool ChangeIntentionStudent(Guid id,int IntentionStudentStatus)
        {
            var model = FindById(id);
            model.IntentionStudentStatus = IntentionStudentStatus;
            return Update(model);
        }
    }
}
